/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.I_ProductCat;

import com.openbravo.bean.Product;
import com.openbravo.bean.ProductCat;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import com.openbravo.pos.bean.ProductExt;

/**
 *
 * @author Administrator
 */
public class ProductCatDAO extends ModifiedLogDAO<ProductCat>{

    public ProductCatDAO(I_Session s) {
        super(s);
    }
    

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(s,
                   "PRODUCTS_CAT",
                    new Field[]{
                new Field(I_ProductCat.PRODUCT, Datas.STRING, Formats.STRING,Product.class),
                new Field(I_ProductCat.CATORDER, Datas.INT, Formats.INT),
                new Field(I_ProductCat.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP)
                },
              new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, ProductCat obj) throws BasicException {
        dp.setString(1,obj.getProductId());
        dp.setInt(2,obj.getCatOrder());
        dp.setTimestamp(3,obj.getLastModified());
    }

    @Override
    public Class getSuportClass() {
        return ProductCat.class;
    }

    public ProductCat readValues(DataRead dr,ProductCat obj) throws BasicException {
        if(obj==null)
        	obj=new ProductCat();
        obj.setProductId(dr.getString(1));
        obj.setCatOrder(dr.getInt(2));
        obj.setLastModified(dr.getTimestamp(3));
        return obj;
    }

    @Override
    public Class transClass(Class in) {
        if(in==ProductExt.class)
            return Product.class;
        return super.transClass(in);
    }
}
